import java.util.Arrays;
/**Created with Interllij IDEA.
 * Descriptiption:
 * User: 王澄慧
 * Date: 2022-04-01
 * Time: 11:13
 */

public class FifthDemo {
    /**
     * 第四种拷贝方法 array.clone()
     * @param args
     */
    public static void main(String[] args) {
        int[] array = {1,2,3,4};
        int[] copy = array.clone();
        System.out.println(Arrays.toString(array));
    }
    /**
     * 第三种拷贝方式System.arraycopy
     * @param args
     */
    public static void main12(String[] args) {
        int[] array = {1, 2, 3, 4};
        int[] copy = Arrays.copyOf(array, array.length);
        System.arraycopy(array,0,copy,0,array.length);
        System.out.println(Arrays.toString(copy));
    }

    /**
     * Arrays.copyof(拷贝你的数组，新的数组）
     * @param args
     */
    public static void main11(String[] args) {
        int[] array = {1, 2, 3, 4};
        int[] copy = Arrays.copyOf(array, array.length);
        System.out.println(Arrays.toString(copy));
    }
    public static void main10(String[] args) {
        int[] array = {2,3,4,5,6};
        int[] copy = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            copy[i] = array[i];
        }
        System.out.println(Arrays.toString(copy));
    }
    public static String myTOString(int[] array){
        String str = "[";
        for (int i = 0; i < array.length ; i++) {
            str = str+array[i]; //字符串拼接
            if(i != array.length-1){
                str += ",";
            }
        }
        str += "]";
        return str;
    }
    public static void main9(String[] args) {
        int[] array = {1,2,3,4};
        String ret = myTOString(array);
        System.out.println(ret);
    }
    public static int[] fun2(){ //数组可以作为返回类型
        int[] array = {1,2,3,4,5};
        return array;
    }
    public static void main8(String[] args) {
        int[] tem = fun2(); //用数组来接收
        System.out.println(Arrays.toString(tem));
    }
    public static void fun(int[] array){
        array = new int[]{1,2,3,4,5}; // new会开辟新的空间
    }
    public static void fun1(int[] array2){
        array2[1] = 19;
    }

    public static void main7(String[] args) {
        int[] array1 = {10,11,12,13};
        fun(array1);
        System.out.println(Arrays.toString(array1));
        int[] array3 = {23,24,25,26};
        fun1(array3);
        System.out.println(Arrays.toString(array3));
    }
    public static void main6(String[] args) {
        int[] array3 = null; // 代表整个引用，不指向任何对象
        int[] array1 = {1,2,3,4}; // 两者不一样
        int[] array2 = {1,2,3,4};
        System.out.println(array1);
        System.out.println(array2);
    }
    public static void main5(String[] args) {
        int[] array = {2,3,4,5,6};
        int[] array1 = array; // 这个引用 array1 指向了array 所指向的对象
        System.out.println("array:" + Arrays.toString(array));
        System.out.println("array1:" + Arrays.toString(array1));
        array1 [0]=100;
        System.out.println("array:" + Arrays.toString(array));
        System.out.println("array1:" + Arrays.toString(array1));
    }
    public static void main4(String[] args) {
        int []array={1,2,3,4,5};
        for ( int a : array ) {
            System.out.print(a + " ");
        }
        System.out.println();
        String ret = Arrays.toString(array);
        System.out.println(ret);
        for (int i = 0; i <= array.length ; i++) {
            System.out.print(array[i]+" ");
        }
    }
    public static void main3(String[] args) {
        int[] array1= {1,2,3,4,5,6,7,8,9,10};
        int[] array2 = new int[]{1,2,3,4,5,6,7,8,9,10};
        String[] array4 = new String[]{"hello","java","wch"};
        int[] array3= new int[10];
        array2[0]=10;
        System.out.println(array4.length);
        System.out.println(array1.length);
        System.out.println(array2.length);
    }
    public static int fun1(int n){
        if(n == 1){
            return 0;
        }
        if(n == 2){
            return 1;
        }
        int f1 = 0;
        int f2 = 1;
        int f3 = 0;
        for (int f = 3; f<= n ; f++) {
            f3 = f1+f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static int fib(int n){
        if(n == 1){
            return 0;
        }
        if(n == 2){
            return 1;
        }
        int tem = fib(n-1)+fib(n-2);
        return tem;
    }
    public static void main2(String[] args) {
        System.out.println(fib(1));
        System.out.println(fib(2));
        System.out.println(fib(42));

    }
    public static void fun(int[] array,int len){
        if (len == 1){
            System.out.println(array[len-1]);
            return;
        }
        fun(array,len-1);
        System.out.println(array[len-1]);
    }
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5};
        fun(array,array.length);
    }
}
